/* 
node.js 的event 模块
*/

const EventEmitter = require('events')

class MyEventEmitter extends EventEmitter {
  constructor(name) {
    super()
    this.name = name
    this.age = 1
    // setInterval(() => {
    //   this.groupUp()
    // }, 2000);
  }
  groupUp () {
    this.age++
    this.emit('groupUp', {name: this.name, age : this.age})
  }
}

const person = new MyEventEmitter('gege')

person.addListener('groupUp', (data) => {
  console.log(`${data.name} group up ${data.age} year`)
})

person.emit('groupUp', { name: 'gege', age: 20 })